//
//  YKWordViewController.m
//  百思不得姐
//
//  Created by Eric.Wu on 16/4/24.
//  Copyright © 2016年 Eric.Wu. All rights reserved.
//

#import "YKWordViewController.h"
#import "YKWordModel.h"
#import "YKListModel.h"
@interface YKWordViewController ()

@property (nonatomic,strong)AFHTTPSessionManager *manager;

@property (nonatomic,strong) NSMutableArray *list;


@end

@implementation YKWordViewController
#pragma mark - 懒加载管理者
- (AFHTTPSessionManager *)manager
{
    if (!_manager) {
        _manager = [AFHTTPSessionManager manager];
    }
    return _manager;
}

- (NSMutableArray *)list
{
    if (!_list ) {
        _list = [[NSMutableArray alloc] init];
    }
    return _list;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadWord];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Identifier"];
    
    self.tableView.contentInset = UIEdgeInsetsMake(64, 0, 55, 0);
    self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)loadWord
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"a"] = @"list";
    params[@"c"] = @"data";
    params[@"type"] = @"29";
    [self.manager GET:@"http://api.budejie.com/api/api_open.php" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        [SVProgressHUD dismiss];
        YKWordModel *model = [YKWordModel objectWithKeyValues:responseObject];
        
        [self.list addObjectsFromArray:model.list];
        [self.tableView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD dismiss];
     
    }];

}


#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Identifier"];
    YKListModel *listModel = self.list[indexPath.row];
     cell.textLabel.text = listModel.text;
    
    return cell;
}


@end
